use strict;
use warnings;
use Math::Calculus::Expression;
use Test::More tests => 2;

BEGIN {
    use_ok 'SPAN::Method::LinearEquation::FalsePosition';
}
my $exp = Math::Calculus::Expression->new;
$exp->addVariable('x');
$exp->setExpression('x^3 + (- 9*x ) + 3') or die $exp->getError;
diag( "\nExpression: " . $exp->getExpression );

my $expected = 0.337635045511401;
diag( "Expected: x=" . $expected );

my $falsePos = SPAN::Method::LinearEquation::FalsePosition->new(
    expression => $exp,
    start      => 0,
    end        => 1,
    precision  => 0.0005
);
my $got = $falsePos->run;
diag( "Got: x=" . $got );

cmp_ok( sprintf( "%.15f", $got ), '==', $expected, 'false position run' );
